

clear *
set more off, permanently
*set your local directory, in which you have saved defaults_donations.dta
cd "[INSERT LOCAL DIRECTORY HERE]"
use defaults_donations.dta, clear


***********************************************************
***********************************************************
*
* TABLE OF CONTENTS
*
*  Figures in Sections 3 
*	Figure 3: Donation distributions by default donation level
*   Figure 4: Average donation by treatment
*   Figure 5: Change in donation distributions due to defaults
*   Figure 6: Average codonation by treatment
*
************************************************************
************************************************************


***************************************
***  Figure 3                       ***
***************************************

 
use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

*drop non-donors
drop if donate==0

*generate donation distributsions by default donation level 
egen numdonations = count(donated_amount), by(default_donation)
egen samedonations = count(donated_amount), by(donated_amount default_donation)
gen donation_freq = samedonations/numdonations

*plot figure
foreach x of numlist 10 20 50{
	twoway (spike donation_freq donated_amount if donated_amount<=100 & default_donation==`x', ///
	lcolor(black) lwidth(vthick) sort graphregion(color(none)) bgcolor(white) lcolor(black) ///
	lwidth(thick) xlabel(0 10 20 50 100, labs(5)) xline(`x', lpattern(longdash) lwidth(thick) lcolor(gs8)) yline(0, lcolor(black)) ///
	lwidth(thick) ylabel(0[.1].3, labs(5)) xtitle(Donated Amount, si(5)) ytitle("Relative Frequency", si(5)) title(`x', si(6)) ///
	lwidth(2.5)) 
	graph save   "donation_freq`x'.gph", replace
}

twoway (spike donation_freq donated_amount if donated_amount<=100 & default_donation==0, ///
		lcolor(black) lwidth(vthick)  sort graphregion(color(none))  bgcolor(white) lcolor(black) ///
		lwidth(thick) xlabel(0 10 20 50 100, labs(5)) yline(0, lcolor(black) lwidth(thick)) ylabel(0[.1].3, labs(5)) ///
		xtitle(Donated Amount, si(5)) ytitle("Relative Frequency", si(5)) title("AD", si(6) ) ///
		lwidth(2.5)) 
graph save  "donation_freq0.gph", replace

graph combine "donation_freq0.gph" "donation_freq10.gph" "donation_freq20.gph" "donation_freq50.gph", ///
		graphregion(color(white)) xcom ycom altshrink scale(1.1)
graph export  "Figure3.pdf", as(pdf) replace



***************************************
***  Figure 4                       ***
***************************************


use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

*calculate clustered s.e. for confidence intervals
gen se_donated_am=.
foreach x in T05 T010 T015 T105 T1010 T1015 T205 T2010 T2015 T505 T5010 T5015{
quietly reg donated_am `x', nocons vce(cluster session)
quietly replace se_donated_am=_se[`x'] if `x'==1
}
bysort treat: egen mean_donated_am=mean(donated_am)
duplicates drop treat mean_donated_am se_donated_am, force

gen umean_donated_am=mean_donated_am + 1.96*se_donated_am
gen lmean_donated_am=mean_donated_am - 1.96*se_donated_am

*plot figure
twoway (bar mean_donated_am treat, fcolor(white) lcolor(black) lwidth(medthick) ) (rcap umean_donated_am lmean_donated_am treat, lcolor(gs8) lwidth(medthick)), ///
 graphregion(color(none) ) bgcolor(white) ylabel(0(.5)2, nogrid format(%9.2fc) ) yscale(range(0 2.2)) ///
 xlabel(0 "(AD,5)" 1 "(AD,10)" 2 "(AD,15)" 3 "(10,5)" 4 "(10,10)" 5 "(10,15)" 6 "(20,5)" 7 "(20,10)" 8 "(20,15)" 9 "(50,5)" 10 "(50,10)" 11 "(50,15)"  ,  ///
 valuelabel angle(90))  xtitle("Treatment") ytitle("Average Donation (EUR)", height(5)) legend(off) scheme(s2mono)
graph export "Figure4.pdf", as(pdf) replace




***************************************
***  Figure 5                       ***
***************************************


*default-specific donation distributions 
mkdir temp
foreach x of numlist 0 10 20 50{
	use defaults_donations.dta, clear
	drop if q99_8==1
	keep donated_a default_donation
	contract donated_a if default_donation==`x', percent(percent`x') freq(freq`x') cfreq(cfreq`x') cpercent(cpercent`x')
	gen default_donation=`x'
	sort donated_amount
	save temp\freq_default_donation_`x', replace
}

use temp\freq_default_donation_0, clear
merge donated_a using temp\freq_default_donation_10
drop _merge
sort donated_a

merge donated_a using temp\freq_default_donation_20
drop _merge
sort donated_a

merge donated_a using temp\freq_default_donation_50
drop _merge
sort donated_a

*calculate differences in distributions under different donation defaults 
foreach x of numlist 0 10 20 50{
replace freq`x'=0 if freq`x'==.
replace percent`x'=0 if percent`x'==.
}
sort donated_a
foreach x in freq percent{
gen `x'10_0=`x'10-`x'0
gen `x'20_0=`x'20-`x'0
gen `x'50_0=`x'50-`x'0
gen `x'20_10=`x'20-`x'10
gen `x'50_10=`x'50-`x'10
gen `x'50_20=`x'50-`x'20
}
drop default*

*plot figure
foreach x of numlist 10 20 50{
sort donated_a
twoway (spike percent`x'_0 donated_a if donated_a<=100, graphregion(color(none)) ///
		bgcolor(white) lwidth(vthick) lcolor(black) xlabel(0 10 20 50 100, labsize(small)) xline(`x', lpattern(longdash) lwidth(medthick) lcolor(gs8)) ///
		lwidth(vthick)  yline(0, lcolor(black)) ylabel(-.4[.2].40,  labsize(small)) xtitle(Donated Amount) ///
		ytitle(Difference (p.p.))  title(`x' vs. AD, size(4)))

graph save  donation_diff`x'_0.gph, replace
graph export  donation_diff`x'_0.png, replace
}
twoway (spike percent20_10 donated_a if donated_a<=100, graphregion(color(none)) ///
		bgcolor(white) lwidth(vthick) lcolor(black) xline(20, lpattern(longdash) lwidth(medthick) lcolor(gs8)) ///
		xline(10, lpattern(longdash) lwidth(medthick) lcolor(gs8)) xlabel(0 10 20 50 100, labsize(small))  lwidth(vthick) ///
		yline(0, lcolor(black)) ylabel(-.4[.2].40, labsize(small)) xtitle(Donated Amount) ///
		ytitle(Difference (p.p.))  title(20 vs. 10, size(4)))
graph save  donation_diff20_10.gph, replace
graph export  donation_diff20_10.png, replace

twoway (spike percent50_10 donated_a if donated_a<=100, graphregion(color(none)) ///
		bgcolor(white) lwidth(vthick) lcolor(black)  xline(50, lpattern(longdash) lwidth(medthick) lcolor(gs8)) ///
		xline(10, lpattern(longdash) lwidth(medthick) lcolor(gs8)) xlabel(0 10 20 50 100, labsize(small))  lwidth(vthick) ///
		yline(0, lcolor(black)) ylabel(-.4[.2].40, labsize(small)) xtitle(Donated Amount) ///
		ytitle(Difference (p.p.))  title(50 vs. 10, size(4)))
graph save  donation_diff50_10.gph, replace
graph export  donation_diff50_10.png, replace

twoway (spike percent50_20 donated_a if donated_a<=100, graphregion(color(none)) ///
		bgcolor(white) lwidth(vthick) lcolor(black)  xline(50, lpattern(longdash) lwidth(medthick) lcolor(gs8))  ///
		xline(20, lpattern(longdash) lwidth(medthick) lcolor(gs8)) xlabel(0 10 20 50 100, labsize(small))  lwidth(vthick) /// 
		yline(0, lcolor(black)) ylabel(-.4[.2].40, labsize(small)) xtitle(Donated Amount) ///
		ytitle(Difference (p.p.))  title(50 vs. 20, size(4)))
		
graph save  donation_diff50_20.gph, replace
graph export  donation_diff50_20.png, replace

graph combine donation_diff10_0.gph donation_diff20_0.gph ///
		donation_diff50_0.gph donation_diff20_10.gph ///
		donation_diff50_10.gph donation_diff50_20.gph, ///
		col(3) row(3) holes(4 7 8) scheme(s1mono) xcommon ycommon altshrink ///
		scale(1.7)
graph export  Figure5.pdf, as(pdf) replace




***************************************
***  Figure 6                       ***
***************************************


use defaults_donations.dta, clear

*drop top 0.2% of donors with highest donation levels
drop if q99_8==1

*calculate clustered s.e. for confidence intervals
gen se_codonated_am=.
foreach x in T05 T010 T015 T105 T1010 T1015 T205 T2010 T2015 T505 T5010 T5015{
quietly reg codonated_am `x', nocons vce(cluster session)
quietly replace se_codonated_am=_se[`x'] if `x'==1
}
bysort treat: egen mean_codonated_am=mean(codonated_am)
duplicates drop treat mean_codonated_am se_codonated_am, force

gen umean_codonated_am=mean_codonated_am + 1.96*se_codonated_am
gen lmean_codonated_am=mean_codonated_am - 1.96*se_codonated_am

*plot figure
twoway (bar mean_codonated_am treat, fcolor(white) lcolor(black) lwidth(medthick) ) (rcap umean_codonated_am lmean_codonated_am treat, lcolor(gs8) lwidth(medthick)), ///
 graphregion(color(none) ) bgcolor(white) ylabel(0(.02).1, nogrid format(%9.2fc) ) yscale(range(0 .105)) ///
 xlabel(0 "(AD,5)" 1 "(AD,10)" 2 "(AD,15)" 3 "(10,5)" 4 "(10,10)" 5 "(10,15)" 6 "(20,5)" 7 "(20,10)" 8 "(20,15)" 9 "(50,5)" 10 "(50,10)" 11 "(50,15)"  ,  ///
 valuelabel angle(90)) xtitle("Treatment" ) ytitle("Average Codonation (EUR)", height(5)) legend(off) scheme(s2mono)
graph export "Figure6.pdf", as(pdf) replace




***************************************
***  Figures 7 & 8                   ***
***************************************


* see readme file for further information on replication code




